<?php
session_start();
require 'connect.php';
?>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <style type="text/css">
            body {
                background-color: aliceblue;
            }
        </style>
        <title>FourBox</title>
    </head>
    <body>
        <table>
            <tr>
                <td width="300"><b>Name</b></td>
                <td width="100"><b>Last Modified</b></td>
                <td width="100"><b>Action</b></td>
            </tr>
    <?php
        $user = $_SESSION["myusername"];
        $dir = $_GET["folder"]."/";
        echo '<h2>'.$user.' FourBox Content</h2>';
        if (is_dir($dir)) {
            if ($dh = opendir($dir)) {
                while (($file = readdir($dh)) != false) {
                    if (($file != ".") && ($file != "..")) {
                        if (filetype($dir . $file) != "dir") {
                            echo '<tr><td>'.$file.'</td>
                                <td>'.date ("F d Y H:i:s.", strtotime(filemtime($dir.'/'.$file))).'</td>
                                <td><a href= "download.php?dir='.$dir.'&download_file='.$file.'">Download</a></td>
                                </tr>';
                        }
                        else if (filetype($dir . $file) == "dir") {
                            echo '<tr>
                                <td>'.$file.'</td>
                                <td></td>
                                <td><a href= "fourbox.php?folder='.$dir."".$file.'">Open</a></td>
                                </tr>';
                        }
                    }
                }
                closedir($dh);
            }
        }
    ?>
        </table>
     </body>
</html>


